package com.shqcjd.preinstallglass.ui.activity.input;

import android.app.Activity;
import android.content.Intent;
import android.widget.Button;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.shqcjd.preinstallglass.R;
import com.shqcjd.preinstallglass.ui.base.BaseActivity;
import com.shqcjd.preinstallglass.ui.base.BasePresenter;

import butterknife.BindView;


public class NumberInputActivity extends BaseActivity {
    private StringBuffer stringBuffer = new StringBuffer();

    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.btn_clean)
    Button btnClean;
    @BindView(R.id.btn_back)
    Button btnBack;
    @BindView(R.id.btn_confirm)
    Button btnConfirm;
    private Activity mActivity;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_number_input;
    }

    @Override
    public void initView() {
        super.initView();
        mActivity = this;
    }

    @Override
    protected String getVoiceContent() {
        return "|点|清除|退格|接受|1|2|3|4|5|6|7|8|9;";
    }

    @Override
    protected void onVoiceResult(String result) {
        Logger.i("识别结果:"+result);
        if (result.equals("点")) {
            if (!stringBuffer.toString().equals("") && stringBuffer.charAt(0) != '.' && !stringBuffer.toString().contains(".")) {
                stringBuffer.append(".");
                tvContent.setText(stringBuffer.toString());
            }

        } else if (result.equals("接受")) {
            Intent it = new Intent();
            it.putExtra("input_key", stringBuffer.toString().trim());
            mActivity.setResult(RESULT_OK, it);
            mActivity.finish();

        } else if (result.equals("退格")) {
            if (!stringBuffer.toString().equals("")) {
                stringBuffer.deleteCharAt(stringBuffer.length() - 1);
                tvContent.setText(stringBuffer.toString());
            }
        } else if (result.equals("清除")) {
            stringBuffer.delete(0, stringBuffer.length());
            tvContent.setText(stringBuffer.toString());
        } else {
            stringBuffer.append(result);
            tvContent.setText(stringBuffer.toString());
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();
    }




}

